package design_patterns_and_best_practices_in_java;

interface PlatformBridge {
    void forwardMessage(String msg);
}

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2019-11-14 下午4:44
 */
public class Chapter4Bridge {
    public static void main(String[] args) {
        new AllMessageClient(new WindowsImplementation()).sendMessageToAll("abc@gmail.com", "test");
    }
}

class WindowsImplementation implements PlatformBridge {

    @Override
    public void forwardMessage(String msg) {
        System.out.printf("sending message n%s nFrom the windows machine", msg);
    }
}

class PosixImplementation implements PlatformBridge {

    @Override
    public void forwardMessage(String msg) {
        System.out.printf("sending message n%s from the linux machine", msg);
    }
}

class MessageSender {
    private PlatformBridge implement;

    public MessageSender(PlatformBridge implement) {
        this.implement = implement;
    }

    public void sendMessage(String from, String to, String body) {
        implement.forwardMessage(String.format("From: %s nTo: %s noBody: %s", from, to, body));
    }
}

class AllMessageClient extends MessageSender {
    private String to = "development_all@abc.com";

    public AllMessageClient(PlatformBridge implement) {
        super(implement);
    }

    public void sendMessageToAll(String from, String body) {
        sendMessage(from, to, body);
    }
}